@financial-times/custom-code-component 2.0.22 → 2.0.25
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/custom-element.d.ts +14 -3
- package/dist/custom-element.js +131 -106
- package/dist/custom-element.js.map +1 -1
- package/package.json +1 -1
- package/src/custom-code-component.ts +64 -28
- package/src/logger.ts +2 -2
- package/src/tracking.ts +11 -6
package/dist/custom-element.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseRenderer } from '../../ccc-sdk/src/renderers/BaseRenderer';
|
|
2
2
|
import { ContentTree } from '@financial-times/content-tree';
|
|
3
|
+
import { default as default_2 } from 'ftdomdelegate/main';
|
|
3
4
|
|
|
4
5
|
declare class ComponentPath {
|
|
5
6
|
org: string;
|
|
@@ -71,6 +72,10 @@ declare class FTCustomCodeComponent extends HTMLElement {
|
|
|
71
72
|
* Logger instance. Set log level using `this.logger.setLogLevel(string|number|null)`.
|
|
72
73
|
*/
|
|
73
74
|
logger: Logger;
|
|
75
|
+
/**
|
|
76
|
+
* Abort controller used to abort async connectedCallback functionality when disconnectedCallback is called`.
|
|
77
|
+
*/
|
|
78
|
+
ac: AbortController | null;
|
|
74
79
|
/**
|
|
75
80
|
* IntersectionObserver that dispatches CCCViewportEvents
|
|
76
81
|
*/
|
|
@@ -141,7 +146,7 @@ declare class FTCustomCodeComponent extends HTMLElement {
|
|
|
141
146
|
*
|
|
142
147
|
* @param prerendered
|
|
143
148
|
*/
|
|
144
|
-
mount(prerendered?: ShadowRoot | null):
|
|
149
|
+
mount(prerendered?: ShadowRoot | null): void;
|
|
145
150
|
/**
|
|
146
151
|
* Called in top-level error handler or by child component on unhandled error.
|
|
147
152
|
* Replace shadow root with either <slot> or template[data-component-fallback]
|
|
@@ -155,7 +160,7 @@ declare class FTCustomCodeComponent extends HTMLElement {
|
|
|
155
160
|
*
|
|
156
161
|
* @returns Promise resolving to component renderer function
|
|
157
162
|
*/
|
|
158
|
-
load(): Promise<(shadowRoot: ShadowRoot, props: any, ssr?: boolean, onErrorCallback?: Function, log?: Logger) => {
|
|
163
|
+
load(signal: AbortSignal): Promise<(shadowRoot: ShadowRoot, props: any, ssr?: boolean, onErrorCallback?: Function, log?: Logger) => {
|
|
159
164
|
onmessage: {
|
|
160
165
|
(...data: any[]): void;
|
|
161
166
|
(message?: any, ...optionalParams: any[]): void;
|
|
@@ -165,7 +170,11 @@ declare class FTCustomCodeComponent extends HTMLElement {
|
|
|
165
170
|
/**
|
|
166
171
|
* Initialises OTracking
|
|
167
172
|
*/
|
|
168
|
-
initTracking: () =>
|
|
173
|
+
initTracking: () => void;
|
|
174
|
+
/**
|
|
175
|
+
* Destroys OTracking to avoid duplicate events
|
|
176
|
+
*/
|
|
177
|
+
destroyTracking: () => void;
|
|
169
178
|
/**
|
|
170
179
|
* Injects Vite HMR scripts during dev environment usage
|
|
171
180
|
*/
|
|
@@ -208,6 +217,7 @@ declare class Tracking {
|
|
|
208
217
|
elements: string | string[];
|
|
209
218
|
isInitialised: boolean;
|
|
210
219
|
log: Logger;
|
|
220
|
+
shadowDelegate: typeof default_2;
|
|
211
221
|
constructor({ id, name, subtype, teamName, shadowRoot, category, elements, logger, }: {
|
|
212
222
|
id?: string;
|
|
213
223
|
name: string;
|
|
@@ -227,6 +237,7 @@ declare class Tracking {
|
|
|
227
237
|
}, root: Element): (clickEvent: Event, clickElement: HTMLElement) => void;
|
|
228
238
|
sendSpoorEvent(triggerAction: any, extraDetail: any): void;
|
|
229
239
|
init(id: string): void;
|
|
240
|
+
destroy(): void;
|
|
230
241
|
}
|
|
231
242
|
|
|
232
243
|
export { }
|
package/dist/custom-element.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function
|
|
2
|
-
this.listenerMap = [{}, {}], o && this.root(o), this.handle =
|
|
1
|
+
function g(o) {
|
|
2
|
+
this.listenerMap = [{}, {}], o && this.root(o), this.handle = g.prototype.handle.bind(this), this._removedListeners = [];
|
|
3
3
|
}
|
|
4
|
-
|
|
4
|
+
g.prototype.root = function(o) {
|
|
5
5
|
const t = this.listenerMap;
|
|
6
6
|
let e;
|
|
7
7
|
if (this.rootElement) {
|
|
@@ -19,10 +19,10 @@ m.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
|
+
g.prototype.captureForType = function(o) {
|
|
23
23
|
return ["blur", "error", "focus", "load", "resize", "scroll"].indexOf(o) !== -1;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
g.prototype.on = function(o, t, e, n) {
|
|
26
26
|
let r, s, i, c;
|
|
27
27
|
if (!o)
|
|
28
28
|
throw new TypeError("Invalid event type: " + o);
|
|
@@ -35,7 +35,7 @@ m.prototype.on = function(o, t, e, n) {
|
|
|
35
35
|
matcherParam: c
|
|
36
36
|
}), this;
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
g.prototype.off = function(o, t, e, n) {
|
|
39
39
|
let r, s, i, c, a;
|
|
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,7 +50,7 @@ m.prototype.off = function(o, t, e, n) {
|
|
|
50
50
|
s = c[r], (!t || t === s.selector) && (!e || e === s.handler) && (this._removedListeners.push(s), c.splice(r, 1));
|
|
51
51
|
return c.length || (delete i[o], this.rootElement && this.rootElement.removeEventListener(o, this.handle, n)), this;
|
|
52
52
|
};
|
|
53
|
-
|
|
53
|
+
g.prototype.handle = function(o) {
|
|
54
54
|
let t, e;
|
|
55
55
|
const n = o.type;
|
|
56
56
|
let r, s, i, c, a = [], h;
|
|
@@ -68,22 +68,22 @@ m.prototype.handle = function(o) {
|
|
|
68
68
|
a = this.listenerMap[0][n];
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
|
-
let
|
|
71
|
+
let p = [];
|
|
72
72
|
for (e = a.length; h && e; ) {
|
|
73
73
|
for (t = 0; t < e && (i = a[t], !!i); t++)
|
|
74
|
-
h.tagName && ["button", "input", "select", "textarea"].indexOf(h.tagName.toLowerCase()) > -1 && h.hasAttribute("disabled") ?
|
|
74
|
+
h.tagName && ["button", "input", "select", "textarea"].indexOf(h.tagName.toLowerCase()) > -1 && h.hasAttribute("disabled") ? p = [] : i.matcher.call(h, i.matcherParam, h) && p.push([o, h, i]);
|
|
75
75
|
if (h === r || (e = a.length, h = h.parentElement || h.parentNode, h instanceof HTMLDocument))
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
|
-
let
|
|
79
|
-
for (t = 0; t <
|
|
80
|
-
if (!(this._removedListeners.indexOf(
|
|
81
|
-
|
|
78
|
+
let m;
|
|
79
|
+
for (t = 0; t < p.length; t++)
|
|
80
|
+
if (!(this._removedListeners.indexOf(p[t][2]) > -1) && (c = this.fire.apply(this, p[t]), c === !1)) {
|
|
81
|
+
p[t][0][l] = !0, p[t][0].preventDefault(), m = !1;
|
|
82
82
|
break;
|
|
83
83
|
}
|
|
84
|
-
return
|
|
84
|
+
return m;
|
|
85
85
|
};
|
|
86
|
-
|
|
86
|
+
g.prototype.fire = function(o, t, e) {
|
|
87
87
|
return e.handler.call(t, o, t);
|
|
88
88
|
};
|
|
89
89
|
function U(o, t) {
|
|
@@ -100,7 +100,7 @@ function _(o, t) {
|
|
|
100
100
|
function D(o, t) {
|
|
101
101
|
return o === t.id;
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
g.prototype.destroy = function() {
|
|
104
104
|
this.off(), this.root();
|
|
105
105
|
};
|
|
106
106
|
function N(o) {
|
|
@@ -110,41 +110,41 @@ function I(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
|
}
|
|
113
|
-
const
|
|
113
|
+
const u = Object.freeze({
|
|
114
114
|
DEBUG: 0,
|
|
115
115
|
INFO: 1,
|
|
116
116
|
WARN: 2,
|
|
117
117
|
ERROR: 3,
|
|
118
118
|
TEST: 4,
|
|
119
119
|
DEFAULT: 2
|
|
120
|
-
}),
|
|
120
|
+
}), w = "CCC:";
|
|
121
121
|
function S(o) {
|
|
122
122
|
const t = o == null ? void 0 : o.toLowerCase();
|
|
123
|
-
return t === "debug" ?
|
|
123
|
+
return t === "debug" ? u.DEBUG : t === "info" ? u.INFO : t === "warn" ? u.WARN : t === "error" ? u.ERROR : t === "test" ? u.TEST : u.DEFAULT;
|
|
124
124
|
}
|
|
125
125
|
class P {
|
|
126
126
|
constructor({
|
|
127
|
-
level: t =
|
|
127
|
+
level: t = u.DEFAULT,
|
|
128
128
|
component: e
|
|
129
129
|
} = {
|
|
130
|
-
level:
|
|
130
|
+
level: u.DEFAULT
|
|
131
131
|
}) {
|
|
132
|
-
this.log = this.debug, this.level = localStorage.getItem("CCC_LOG_LEVEL") ? S(localStorage.getItem("CCC_LOG_LEVEL")) : t, this.component = e;
|
|
132
|
+
this.log = this.debug, this.level = localStorage != null && localStorage.getItem("CCC_LOG_LEVEL") ? S(localStorage.getItem("CCC_LOG_LEVEL")) : t, this.component = e;
|
|
133
133
|
}
|
|
134
134
|
debug(...t) {
|
|
135
|
-
this.level <=
|
|
135
|
+
this.level <= u.DEBUG && console.info(w, ...t, this.component);
|
|
136
136
|
}
|
|
137
137
|
info(...t) {
|
|
138
|
-
this.level <=
|
|
138
|
+
this.level <= u.INFO && console.info(w, ...t, this.component);
|
|
139
139
|
}
|
|
140
140
|
warn(...t) {
|
|
141
|
-
this.level <=
|
|
141
|
+
this.level <= u.WARN && console.warn(w, ...t, this.component);
|
|
142
142
|
}
|
|
143
143
|
error(...t) {
|
|
144
|
-
this.level <=
|
|
144
|
+
this.level <= u.ERROR && console.error(w, ...t, this.component);
|
|
145
145
|
}
|
|
146
146
|
setLogLevel(t) {
|
|
147
|
-
localStorage.getItem("CCC_LOG_LEVEL") ? this.level = S(localStorage.getItem("CCC_LOG_LEVEL")) : typeof t == "number" ? this.level = t : this.level = S(t);
|
|
147
|
+
localStorage != null && localStorage.getItem("CCC_LOG_LEVEL") ? this.level = S(localStorage.getItem("CCC_LOG_LEVEL")) : typeof t == "number" ? this.level = t : this.level = S(t);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
const M = (o, t, e) => {
|
|
@@ -168,17 +168,17 @@ const M = (o, t, e) => {
|
|
|
168
168
|
n !== void 0 && (typeof n == "boolean" ? t[e] = n : t[e] = N(n));
|
|
169
169
|
}
|
|
170
170
|
return t;
|
|
171
|
-
},
|
|
171
|
+
}, V = (o) => {
|
|
172
172
|
try {
|
|
173
173
|
const t = JSON.parse(o), e = Object.prototype.toString.call(t);
|
|
174
174
|
return [e === "[object Object]" || e === "[object Array]", t];
|
|
175
175
|
} catch {
|
|
176
176
|
return [!1, null];
|
|
177
177
|
}
|
|
178
|
-
},
|
|
179
|
-
const [t, e] =
|
|
178
|
+
}, j = (o) => {
|
|
179
|
+
const [t, e] = V(o);
|
|
180
180
|
return t ? e : o;
|
|
181
|
-
},
|
|
181
|
+
}, H = (o, t) => (o.filter(
|
|
182
182
|
(e) => e.name.match(/^data-trackable|^data-o-|^aria-/i)
|
|
183
183
|
).forEach((e) => {
|
|
184
184
|
t[e.name] = e.value;
|
|
@@ -187,14 +187,14 @@ const M = (o, t, e) => {
|
|
|
187
187
|
return e && x.forEach((r) => {
|
|
188
188
|
typeof t[r] < "u" && r !== "id" && (n[r] = t[r]);
|
|
189
189
|
}), o.filter((r) => r.name.match(/^data-trackable-context-/i)).forEach((r) => {
|
|
190
|
-
n[r.name.replace("data-trackable-context-", "")] =
|
|
190
|
+
n[r.name.replace("data-trackable-context-", "")] = j(r.value);
|
|
191
191
|
}), n;
|
|
192
192
|
};
|
|
193
193
|
function z(o, t) {
|
|
194
194
|
const e = o, n = e != null && e.getAttribute("data-trackable") ? `[data-trackable="${e.getAttribute("data-trackable")}"]` : e == null ? void 0 : e.nodeName, r = [], s = {};
|
|
195
195
|
for (; o && o !== t; ) {
|
|
196
196
|
const i = F(o), c = Array.from(o.attributes);
|
|
197
|
-
let a =
|
|
197
|
+
let a = H(c, i);
|
|
198
198
|
a["data-trackable"] && (a = Object.assign(
|
|
199
199
|
a,
|
|
200
200
|
M(o, e, n)
|
|
@@ -279,23 +279,27 @@ class G {
|
|
|
279
279
|
action: "click",
|
|
280
280
|
category: this.category
|
|
281
281
|
}, r = (e = this.shadowRoot) == null ? void 0 : e.querySelector("[data-component-root]");
|
|
282
|
-
r && new
|
|
282
|
+
r && (this.shadowDelegate = new g(r), this.shadowDelegate.on(
|
|
283
283
|
"click",
|
|
284
284
|
this.elements,
|
|
285
285
|
this.handleClickEvent(n, r),
|
|
286
286
|
!0
|
|
287
|
-
);
|
|
287
|
+
));
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
+
destroy() {
|
|
291
|
+
var t;
|
|
292
|
+
(t = this.shadowDelegate) == null || t.off();
|
|
293
|
+
}
|
|
290
294
|
}
|
|
291
|
-
class
|
|
295
|
+
class d {
|
|
292
296
|
constructor(t) {
|
|
293
297
|
this.org = "local", this.repo = "dev";
|
|
294
|
-
const { org: e, repo: n, name: r, versionRange: s } =
|
|
298
|
+
const { org: e, repo: n, name: r, versionRange: s } = T(t) ? t : d.fromString(t);
|
|
295
299
|
e && (this.org = e), n && (this.repo = n), this.name = r, this.versionRange = s;
|
|
296
300
|
}
|
|
297
301
|
set path(t) {
|
|
298
|
-
const { org: e, repo: n, name: r, versionRange: s } =
|
|
302
|
+
const { org: e, repo: n, name: r, versionRange: s } = T(t) ? t : d.fromString(t);
|
|
299
303
|
this.org = e, this.repo = n, this.name = r, this.versionRange = s;
|
|
300
304
|
}
|
|
301
305
|
get path() {
|
|
@@ -312,42 +316,42 @@ class g {
|
|
|
312
316
|
static fromString(t, e) {
|
|
313
317
|
var a;
|
|
314
318
|
const n = t ?? "unknown/unknown/unknown", [r, s, i] = n.replace(/@[^\/]+/, "").split("/").reverse(), c = e ?? ((a = n.match(/@[^\/]+/)) == null ? void 0 : a.toString().replace("@", "")) ?? "unknown";
|
|
315
|
-
if (s && !c) throw new
|
|
316
|
-
return new
|
|
319
|
+
if (s && !c) throw new f("No version specified");
|
|
320
|
+
return new d({ org: i, repo: s, name: r, versionRange: c });
|
|
317
321
|
}
|
|
318
322
|
}
|
|
319
|
-
function
|
|
323
|
+
function T(o) {
|
|
320
324
|
return typeof o == "object" && o !== null ? "org" in o && "repo" in o && "name" in o : !1;
|
|
321
325
|
}
|
|
322
|
-
class
|
|
326
|
+
class f extends Error {
|
|
323
327
|
constructor(t, e) {
|
|
324
328
|
var n;
|
|
325
329
|
!e && t ? (super(t), this.component = null) : typeof (e == null ? void 0 : e.component) == "string" ? (super(
|
|
326
330
|
t ?? `${e.cause ?? "Unknown error"} in ${e.component} imported from ${e.source ?? "an undefined source"}.`
|
|
327
|
-
), this.component =
|
|
331
|
+
), this.component = d.fromString(e.component)) : T(e == null ? void 0 : e.component) ? (super(
|
|
328
332
|
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"}.`
|
|
329
|
-
), this.component = new
|
|
333
|
+
), this.component = new d(e.component)) : (super(
|
|
330
334
|
`${(e == null ? void 0 : e.cause) ?? "Unknown error"} in unknown component imported from ${(e == null ? void 0 : e.source) ?? "unknown source"}.`
|
|
331
|
-
), this.component = null), this.source = (e == null ? void 0 : e.source) ?? "unknown source", this.errors = [], e != null && e.error && ((n = this.errors) == null || n.push(e == null ? void 0 : e.error)), Error.captureStackTrace && Error.captureStackTrace(this,
|
|
335
|
+
), this.component = null), this.source = (e == null ? void 0 : e.source) ?? "unknown source", this.errors = [], e != null && e.error && ((n = this.errors) == null || n.push(e == null ? void 0 : e.error)), Error.captureStackTrace && Error.captureStackTrace(this, f), this.name = "CCCError";
|
|
332
336
|
}
|
|
333
337
|
}
|
|
334
|
-
class
|
|
338
|
+
class E extends f {
|
|
335
339
|
constructor(t, e) {
|
|
336
340
|
super(t, { ...e, cause: "Import error" }), this.name = "CCCImportError";
|
|
337
341
|
}
|
|
338
342
|
}
|
|
339
|
-
class O extends
|
|
343
|
+
class O extends f {
|
|
340
344
|
constructor(t, e) {
|
|
341
345
|
super(t, { ...e, cause: "Render error" }), this.name = "CCCRenderError";
|
|
342
346
|
}
|
|
343
347
|
}
|
|
344
|
-
class J extends
|
|
348
|
+
class J extends f {
|
|
345
349
|
constructor(t) {
|
|
346
350
|
super(null, { ...t, cause: "Timeout error" }), this.name = "CCCTimeoutError";
|
|
347
351
|
}
|
|
348
352
|
}
|
|
349
|
-
const
|
|
350
|
-
constructor(t =
|
|
353
|
+
const y = class y extends Event {
|
|
354
|
+
constructor(t = y.eventType, e, n) {
|
|
351
355
|
super(t, {
|
|
352
356
|
bubbles: !0,
|
|
353
357
|
cancelable: !1,
|
|
@@ -356,54 +360,54 @@ const E = class E extends Event {
|
|
|
356
360
|
}), this.component = e.component, this.source = e.source;
|
|
357
361
|
}
|
|
358
362
|
};
|
|
359
|
-
|
|
360
|
-
let
|
|
361
|
-
const
|
|
363
|
+
y.eventType = "ccc:event";
|
|
364
|
+
let b = y;
|
|
365
|
+
const v = class v extends b {
|
|
362
366
|
constructor(t, e) {
|
|
363
|
-
super(
|
|
367
|
+
super(v.eventType, t, e);
|
|
364
368
|
}
|
|
365
369
|
};
|
|
366
|
-
|
|
367
|
-
let
|
|
368
|
-
const
|
|
370
|
+
v.eventType = "ccc:connected";
|
|
371
|
+
let k = v;
|
|
372
|
+
const C = class C extends b {
|
|
369
373
|
constructor(t, e) {
|
|
370
|
-
super(
|
|
374
|
+
super(C.eventType, t, e);
|
|
371
375
|
}
|
|
372
376
|
};
|
|
373
|
-
|
|
374
|
-
let
|
|
375
|
-
const
|
|
377
|
+
C.eventType = "ccc:ready";
|
|
378
|
+
let A = C;
|
|
379
|
+
const L = class L extends b {
|
|
376
380
|
constructor(t, e) {
|
|
377
|
-
super(
|
|
381
|
+
super(L.eventType, t, e), this.intersecting = !1, this.intersecting = t.intersecting, this.entry = t.entry;
|
|
378
382
|
}
|
|
379
383
|
};
|
|
380
|
-
|
|
381
|
-
let R =
|
|
384
|
+
L.eventType = "ccc:viewport";
|
|
385
|
+
let R = L;
|
|
382
386
|
const W = (o) => o.replace(
|
|
383
387
|
/[A-Z]+(?![a-z])|[A-Z]/g,
|
|
384
388
|
(t, e) => (e ? "-" : "") + t.toLowerCase()
|
|
385
389
|
);
|
|
386
390
|
function K(o) {
|
|
387
|
-
return
|
|
391
|
+
return $([
|
|
388
392
|
"localhost",
|
|
389
393
|
"local.ft.com",
|
|
390
394
|
/^.*\.apps\.in\.ft\.com$/
|
|
391
395
|
], o);
|
|
392
396
|
}
|
|
393
397
|
function B() {
|
|
394
|
-
return
|
|
398
|
+
return $([
|
|
395
399
|
"localhost",
|
|
396
400
|
"local.ft.com",
|
|
397
401
|
/^.*\.in\.ft\.com$/
|
|
398
402
|
], window.location.hostname);
|
|
399
403
|
}
|
|
400
404
|
function Z() {
|
|
401
|
-
return
|
|
405
|
+
return $([
|
|
402
406
|
"spark.ft.com",
|
|
403
407
|
"spark-staging.ft.com"
|
|
404
408
|
], window.location.host);
|
|
405
409
|
}
|
|
406
|
-
function
|
|
410
|
+
function $(o, t) {
|
|
407
411
|
return t ? o.some((e) => typeof e == "string" ? e === t : e.test(t)) : !1;
|
|
408
412
|
}
|
|
409
413
|
function X(o) {
|
|
@@ -449,7 +453,7 @@ class et extends HTMLElement {
|
|
|
449
453
|
"shadow-open",
|
|
450
454
|
"env",
|
|
451
455
|
"load-timeout"
|
|
452
|
-
]), this.component = new
|
|
456
|
+
]), this.component = new d(), this.ac = null, this.observer = new IntersectionObserver((e) => {
|
|
453
457
|
this.logger.debug("Intersection Observer callback", { entries: e }), e.forEach((n) => {
|
|
454
458
|
this.dispatchEvent(
|
|
455
459
|
new R({
|
|
@@ -460,7 +464,7 @@ class et extends HTMLElement {
|
|
|
460
464
|
})
|
|
461
465
|
);
|
|
462
466
|
});
|
|
463
|
-
}), this.channel = new MessageChannel(), this.initTracking =
|
|
467
|
+
}), this.channel = new MessageChannel(), this.initTracking = () => {
|
|
464
468
|
var e;
|
|
465
469
|
this.logger.debug("initTracking", { cccId: this.id });
|
|
466
470
|
try {
|
|
@@ -471,6 +475,17 @@ class et extends HTMLElement {
|
|
|
471
475
|
`Error initialising tracking on <custom-code-component> ${r}@${s}`
|
|
472
476
|
), this.logger.error(n);
|
|
473
477
|
}
|
|
478
|
+
}, this.destroyTracking = () => {
|
|
479
|
+
var e;
|
|
480
|
+
this.logger.debug("destroyTracking", { cccId: this.id });
|
|
481
|
+
try {
|
|
482
|
+
(e = this.tracking) == null || e.destroy();
|
|
483
|
+
} catch (n) {
|
|
484
|
+
const r = this.getAttribute("path"), s = this.getAttribute("version");
|
|
485
|
+
this.logger.info(
|
|
486
|
+
`Error destroying tracking on <custom-code-component> ${r}@${s}`
|
|
487
|
+
), this.logger.error(n);
|
|
488
|
+
}
|
|
474
489
|
}, this.injectViteScripts = () => {
|
|
475
490
|
var r, s;
|
|
476
491
|
if (document.querySelector('script[name="ccc-sdk-react-preamble"]')) return;
|
|
@@ -498,13 +513,14 @@ class et extends HTMLElement {
|
|
|
498
513
|
* Called whenever a <custom-code-component> element is mounted to the DOM.
|
|
499
514
|
*/
|
|
500
515
|
async connectedCallback() {
|
|
516
|
+
var t;
|
|
501
517
|
try {
|
|
502
|
-
const
|
|
503
|
-
this.component =
|
|
504
|
-
} catch (
|
|
505
|
-
|
|
506
|
-
this.emitError(
|
|
507
|
-
}), this.unmount(
|
|
518
|
+
const e = this.getAttribute("path"), n = this.getAttribute("version");
|
|
519
|
+
this.component = d.fromString(e, n), this.logger.component = this.component, this.logger.setLogLevel(this.getAttribute("log")), this.logger.debug("connectedCallback"), (t = this.ac) == null || t.abort(), this.ac = new AbortController(), this.app = await this.load(this.ac.signal), this.mount(), this.initTracking();
|
|
520
|
+
} catch (e) {
|
|
521
|
+
e instanceof Error && requestAnimationFrame(() => {
|
|
522
|
+
this.emitError(e);
|
|
523
|
+
}), this.unmount(e);
|
|
508
524
|
}
|
|
509
525
|
}
|
|
510
526
|
/**
|
|
@@ -513,7 +529,7 @@ class et extends HTMLElement {
|
|
|
513
529
|
* @param error
|
|
514
530
|
*/
|
|
515
531
|
emitError(t) {
|
|
516
|
-
if (this.logger.debug("emitError", { error: t }), t instanceof
|
|
532
|
+
if (this.logger.debug("emitError", { error: t }), t instanceof f)
|
|
517
533
|
this.dispatchEvent(
|
|
518
534
|
new ErrorEvent("ccc:error", {
|
|
519
535
|
bubbles: !0,
|
|
@@ -524,7 +540,7 @@ class et extends HTMLElement {
|
|
|
524
540
|
})
|
|
525
541
|
);
|
|
526
542
|
else {
|
|
527
|
-
const e = new
|
|
543
|
+
const e = new f(t.message, {
|
|
528
544
|
component: this.component,
|
|
529
545
|
error: t
|
|
530
546
|
});
|
|
@@ -545,9 +561,10 @@ class et extends HTMLElement {
|
|
|
545
561
|
* Called when a <custom-code-component> element is removed from DOM.
|
|
546
562
|
*/
|
|
547
563
|
disconnectedCallback() {
|
|
548
|
-
|
|
564
|
+
var e;
|
|
565
|
+
(e = this.ac) == null || e.abort(), this.logger.debug("disconnectedCallback");
|
|
549
566
|
const t = this.getAttribute("path");
|
|
550
|
-
this.logger.info(`<custom-code-component:${t}> disconnected`), this.observer.disconnect();
|
|
567
|
+
this.destroyTracking(), this.logger.info(`<custom-code-component:${t}> disconnected`), this.observer.disconnect();
|
|
551
568
|
}
|
|
552
569
|
/**
|
|
553
570
|
* MessageChannel postMessage callback
|
|
@@ -583,7 +600,7 @@ class et extends HTMLElement {
|
|
|
583
600
|
async onready(t) {
|
|
584
601
|
try {
|
|
585
602
|
await t, this.logger.debug("onready", { app: t }), this.dispatchEvent(
|
|
586
|
-
new
|
|
603
|
+
new A({
|
|
587
604
|
component: this.component,
|
|
588
605
|
source: this.source
|
|
589
606
|
})
|
|
@@ -617,7 +634,7 @@ class et extends HTMLElement {
|
|
|
617
634
|
*
|
|
618
635
|
* @param prerendered
|
|
619
636
|
*/
|
|
620
|
-
|
|
637
|
+
mount(t) {
|
|
621
638
|
var e, n;
|
|
622
639
|
this.logger.debug("mount", t);
|
|
623
640
|
try {
|
|
@@ -626,7 +643,7 @@ class et extends HTMLElement {
|
|
|
626
643
|
throw new Error("CCC mounted without App");
|
|
627
644
|
const r = this.shadowRoot !== null, s = this.shadowRoot ?? this.attachShadow({ mode: this.mode });
|
|
628
645
|
if (this.dispatchEvent(
|
|
629
|
-
new
|
|
646
|
+
new k({
|
|
630
647
|
component: this.component,
|
|
631
648
|
source: this.source
|
|
632
649
|
})
|
|
@@ -697,63 +714,71 @@ class et extends HTMLElement {
|
|
|
697
714
|
*
|
|
698
715
|
* @returns Promise resolving to component renderer function
|
|
699
716
|
*/
|
|
700
|
-
async load() {
|
|
701
|
-
var
|
|
717
|
+
async load(t) {
|
|
718
|
+
var a;
|
|
702
719
|
if (this.logger.debug("load"), !this.component.isValid)
|
|
703
720
|
throw new Error("No path found");
|
|
704
|
-
const
|
|
705
|
-
this.testUrl = X(
|
|
706
|
-
const
|
|
721
|
+
const e = this.getAttribute("path"), n = this.getAttribute("version"), r = Number(this.getAttribute("load-timeout") || 1e4), s = this.getAttribute("test-env");
|
|
722
|
+
this.testUrl = X(s);
|
|
723
|
+
const i = await Q(
|
|
707
724
|
this.component.name,
|
|
708
725
|
this.testUrl
|
|
709
|
-
),
|
|
710
|
-
|
|
726
|
+
), c = this.getAttribute("id");
|
|
727
|
+
i && this.testUrl && (this.logger.debug("load adding Vite scripts"), this.injectViteScripts()), this.source = i ? `${(a = this.testUrl) == null ? void 0 : a.origin}/src/${this.component.name}/index.jsx?id=${c}` : `https://www.ft.com/__component/${this.component.org}/${this.component.repo}${n ? `@${n}` : "@latest"}/${this.component.name}/${this.component.name}.js?id=${c}`;
|
|
711
728
|
try {
|
|
712
729
|
return await new Promise(
|
|
713
|
-
(
|
|
714
|
-
|
|
715
|
-
|
|
730
|
+
(h, l) => {
|
|
731
|
+
t.throwIfAborted();
|
|
732
|
+
const p = setTimeout(() => {
|
|
733
|
+
this.logger.error("CCC import timeout error"), l(
|
|
716
734
|
new J({
|
|
717
735
|
component: this.component,
|
|
718
736
|
source: this.source
|
|
719
737
|
})
|
|
720
738
|
);
|
|
721
|
-
}, Number(
|
|
739
|
+
}, Number(r));
|
|
722
740
|
if (this.source)
|
|
723
741
|
import(
|
|
724
742
|
/* webpackIgnore: true */
|
|
725
743
|
this.source
|
|
726
744
|
/* @vite-ignore */
|
|
727
|
-
).then(({ default:
|
|
728
|
-
if (
|
|
729
|
-
clearTimeout(
|
|
745
|
+
).then(({ default: m }) => {
|
|
746
|
+
if (m)
|
|
747
|
+
clearTimeout(p), h(m);
|
|
730
748
|
else
|
|
731
|
-
throw new
|
|
749
|
+
throw new E(
|
|
732
750
|
"No component renderer default export found",
|
|
733
751
|
{
|
|
734
752
|
component: this.component,
|
|
735
753
|
source: this.source
|
|
736
754
|
}
|
|
737
755
|
);
|
|
738
|
-
}).catch((
|
|
739
|
-
clearTimeout(
|
|
740
|
-
new
|
|
756
|
+
}).catch((m) => {
|
|
757
|
+
clearTimeout(p), this.logger.error(m), m instanceof Error && !(m instanceof E) ? l(
|
|
758
|
+
new E(m.message, {
|
|
741
759
|
component: this.component,
|
|
742
760
|
source: this.source
|
|
743
761
|
})
|
|
744
|
-
) :
|
|
762
|
+
) : l(m);
|
|
745
763
|
});
|
|
746
764
|
else
|
|
747
|
-
throw clearTimeout(
|
|
765
|
+
throw clearTimeout(p), new E(`Unable to mount ${e}`, {
|
|
748
766
|
component: this.component,
|
|
749
767
|
source: this.source
|
|
750
768
|
});
|
|
769
|
+
t.addEventListener(
|
|
770
|
+
"abort",
|
|
771
|
+
() => {
|
|
772
|
+
l(t.reason);
|
|
773
|
+
},
|
|
774
|
+
{ once: !0 }
|
|
775
|
+
);
|
|
751
776
|
}
|
|
752
777
|
);
|
|
753
|
-
} catch (
|
|
778
|
+
} catch (h) {
|
|
754
779
|
throw this.logger.error(
|
|
755
|
-
`<custom-code-component> error during import from ${
|
|
756
|
-
),
|
|
780
|
+
`<custom-code-component> error during import from ${e}@${n}`
|
|
781
|
+
), h;
|
|
757
782
|
}
|
|
758
783
|
}
|
|
759
784
|
/**
|