@financial-times/custom-code-component 2.0.1-beta.7 → 2.0.1-beta.9
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 +4 -594
- package/dist/CustomCodeComponent.js.map +1 -1
- package/dist/custom-element.d.ts +114 -0
- package/dist/custom-element.js +604 -0
- package/dist/custom-element.js.map +1 -0
- package/package.json +7 -2
- package/src/custom-code-component.css +11 -0
- package/src/custom-code-component.ts +35 -27
- package/src/errors.ts +7 -3
- package/src/events.ts +1 -1
- package/src/path.ts +1 -0
- /package/dist/{CustomCodeComponent.d.ts → index.d.ts} +0 -0
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
function l(o) {
|
|
2
|
+
this.listenerMap = [{}, {}], o && this.root(o), this.handle = l.prototype.handle.bind(this), this._removedListeners = [];
|
|
3
|
+
}
|
|
4
|
+
l.prototype.root = function(o) {
|
|
5
|
+
const t = this.listenerMap;
|
|
6
|
+
let e;
|
|
7
|
+
if (this.rootElement) {
|
|
8
|
+
for (e in t[1])
|
|
9
|
+
t[1].hasOwnProperty(e) && this.rootElement.removeEventListener(e, this.handle, !0);
|
|
10
|
+
for (e in t[0])
|
|
11
|
+
t[0].hasOwnProperty(e) && this.rootElement.removeEventListener(e, this.handle, !1);
|
|
12
|
+
}
|
|
13
|
+
if (!o || !o.addEventListener)
|
|
14
|
+
return this.rootElement && delete this.rootElement, this;
|
|
15
|
+
this.rootElement = o;
|
|
16
|
+
for (e in t[1])
|
|
17
|
+
t[1].hasOwnProperty(e) && this.rootElement.addEventListener(e, this.handle, !0);
|
|
18
|
+
for (e in t[0])
|
|
19
|
+
t[0].hasOwnProperty(e) && this.rootElement.addEventListener(e, this.handle, !1);
|
|
20
|
+
return this;
|
|
21
|
+
};
|
|
22
|
+
l.prototype.captureForType = function(o) {
|
|
23
|
+
return ["blur", "error", "focus", "load", "resize", "scroll"].indexOf(o) !== -1;
|
|
24
|
+
};
|
|
25
|
+
l.prototype.on = function(o, t, e, n) {
|
|
26
|
+
let r, s, i, c;
|
|
27
|
+
if (!o)
|
|
28
|
+
throw new TypeError("Invalid event type: " + o);
|
|
29
|
+
if (typeof t == "function" && (n = e, e = t, t = null), n === void 0 && (n = this.captureForType(o)), typeof e != "function")
|
|
30
|
+
throw new TypeError("Handler must be a type of Function");
|
|
31
|
+
return r = this.rootElement, s = this.listenerMap[n ? 1 : 0], s[o] || (r && r.addEventListener(o, this.handle, n), s[o] = []), t ? /^[a-z]+$/i.test(t) ? (c = t, i = R) : /^#[a-z0-9\-_]+$/i.test(t) ? (c = t.slice(1), i = k) : (c = t, i = Element.prototype.matches) : (c = null, i = L.bind(this)), s[o].push({
|
|
32
|
+
selector: t,
|
|
33
|
+
handler: e,
|
|
34
|
+
matcher: i,
|
|
35
|
+
matcherParam: c
|
|
36
|
+
}), this;
|
|
37
|
+
};
|
|
38
|
+
l.prototype.off = function(o, t, e, n) {
|
|
39
|
+
let r, s, i, c, h;
|
|
40
|
+
if (typeof t == "function" && (n = e, e = t, t = null), n === void 0)
|
|
41
|
+
return this.off(o, t, e, !0), this.off(o, t, e, !1), this;
|
|
42
|
+
if (i = this.listenerMap[n ? 1 : 0], !o) {
|
|
43
|
+
for (h in i)
|
|
44
|
+
i.hasOwnProperty(h) && this.off(h, t, e);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
if (c = i[o], !c || !c.length)
|
|
48
|
+
return this;
|
|
49
|
+
for (r = c.length - 1; r >= 0; r--)
|
|
50
|
+
s = c[r], (!t || t === s.selector) && (!e || e === s.handler) && (this._removedListeners.push(s), c.splice(r, 1));
|
|
51
|
+
return c.length || (delete i[o], this.rootElement && this.rootElement.removeEventListener(o, this.handle, n)), this;
|
|
52
|
+
};
|
|
53
|
+
l.prototype.handle = function(o) {
|
|
54
|
+
let t, e;
|
|
55
|
+
const n = o.type;
|
|
56
|
+
let r, s, i, c, h = [], a;
|
|
57
|
+
const m = "ftLabsDelegateIgnore";
|
|
58
|
+
if (o[m] === !0)
|
|
59
|
+
return;
|
|
60
|
+
switch (a = o.target, a.nodeType === 3 && (a = a.parentNode), a.correspondingUseElement && (a = a.correspondingUseElement), r = this.rootElement, s = o.eventPhase || (o.target !== o.currentTarget ? 3 : 2), s) {
|
|
61
|
+
case 1:
|
|
62
|
+
h = this.listenerMap[1][n];
|
|
63
|
+
break;
|
|
64
|
+
case 2:
|
|
65
|
+
this.listenerMap[0] && this.listenerMap[0][n] && (h = h.concat(this.listenerMap[0][n])), this.listenerMap[1] && this.listenerMap[1][n] && (h = h.concat(this.listenerMap[1][n]));
|
|
66
|
+
break;
|
|
67
|
+
case 3:
|
|
68
|
+
h = this.listenerMap[0][n];
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
let u = [];
|
|
72
|
+
for (e = h.length; a && e; ) {
|
|
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
|
+
if (a === r || (e = h.length, a = a.parentElement || a.parentNode, a instanceof HTMLDocument))
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
let v;
|
|
79
|
+
for (t = 0; t < u.length; t++)
|
|
80
|
+
if (!(this._removedListeners.indexOf(u[t][2]) > -1) && (c = this.fire.apply(this, u[t]), c === !1)) {
|
|
81
|
+
u[t][0][m] = !0, u[t][0].preventDefault(), v = !1;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
return v;
|
|
85
|
+
};
|
|
86
|
+
l.prototype.fire = function(o, t, e) {
|
|
87
|
+
return e.handler.call(t, o, t);
|
|
88
|
+
};
|
|
89
|
+
function R(o, t) {
|
|
90
|
+
return o.toLowerCase() === t.tagName.toLowerCase();
|
|
91
|
+
}
|
|
92
|
+
function L(o, t) {
|
|
93
|
+
return this.rootElement === window ? (
|
|
94
|
+
// Match the outer document (dispatched from document)
|
|
95
|
+
t === document || // The <html> element (dispatched from document.body or document.documentElement)
|
|
96
|
+
t === document.documentElement || // Or the window itself (dispatched from window)
|
|
97
|
+
t === window
|
|
98
|
+
) : this.rootElement === t;
|
|
99
|
+
}
|
|
100
|
+
function k(o, t) {
|
|
101
|
+
return o === t.id;
|
|
102
|
+
}
|
|
103
|
+
l.prototype.destroy = function() {
|
|
104
|
+
this.off(), this.root();
|
|
105
|
+
};
|
|
106
|
+
function C(o) {
|
|
107
|
+
return typeof o == "string" ? o.trim() : o;
|
|
108
|
+
}
|
|
109
|
+
function S(o, t) {
|
|
110
|
+
for (const e in o)
|
|
111
|
+
t[e] ? console.warn(`You can't set a custom property called ${e}`) : t[e] = o[e];
|
|
112
|
+
}
|
|
113
|
+
const p = Object.freeze({
|
|
114
|
+
DEBUG: 0,
|
|
115
|
+
INFO: 1,
|
|
116
|
+
WARN: 2,
|
|
117
|
+
ERROR: 3,
|
|
118
|
+
TEST: 4,
|
|
119
|
+
DEFAULT: 2
|
|
120
|
+
});
|
|
121
|
+
function $(o) {
|
|
122
|
+
const t = o == null ? void 0 : o.toLowerCase();
|
|
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
|
+
}
|
|
125
|
+
class T {
|
|
126
|
+
constructor({ level: t = p.DEFAULT } = {
|
|
127
|
+
level: p.DEFAULT
|
|
128
|
+
}) {
|
|
129
|
+
this.log = this.debug, this.level = t;
|
|
130
|
+
}
|
|
131
|
+
debug(...t) {
|
|
132
|
+
this.level <= p.DEBUG && console.info(...t);
|
|
133
|
+
}
|
|
134
|
+
info(...t) {
|
|
135
|
+
this.level <= p.INFO && console.info(...t);
|
|
136
|
+
}
|
|
137
|
+
warn(...t) {
|
|
138
|
+
this.level <= p.WARN && console.warn(...t);
|
|
139
|
+
}
|
|
140
|
+
error(...t) {
|
|
141
|
+
this.level <= p.ERROR && console.error(...t);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const N = (o, t, e) => {
|
|
145
|
+
const n = Array.from((o == null ? void 0 : o.querySelectorAll(e)) ?? []), r = n.findIndex((s) => s === t);
|
|
146
|
+
if (r !== -1)
|
|
147
|
+
return {
|
|
148
|
+
siblings: n.length,
|
|
149
|
+
position: r
|
|
150
|
+
};
|
|
151
|
+
}, A = [
|
|
152
|
+
"nodeName",
|
|
153
|
+
"className",
|
|
154
|
+
"id",
|
|
155
|
+
"href",
|
|
156
|
+
"text",
|
|
157
|
+
"role"
|
|
158
|
+
], O = (o) => {
|
|
159
|
+
const t = {};
|
|
160
|
+
for (const e of A) {
|
|
161
|
+
const n = o[e] || o.getAttribute(e) || o.hasAttribute(e);
|
|
162
|
+
n !== void 0 && (typeof n == "boolean" ? t[e] = n : t[e] = C(n));
|
|
163
|
+
}
|
|
164
|
+
return t;
|
|
165
|
+
}, P = (o) => {
|
|
166
|
+
try {
|
|
167
|
+
const t = JSON.parse(o), e = Object.prototype.toString.call(t);
|
|
168
|
+
return [e === "[object Object]" || e === "[object Array]", t];
|
|
169
|
+
} catch {
|
|
170
|
+
return [!1, null];
|
|
171
|
+
}
|
|
172
|
+
}, x = (o) => {
|
|
173
|
+
const [t, e] = P(o);
|
|
174
|
+
return t ? e : o;
|
|
175
|
+
}, D = (o, t) => (o.filter(
|
|
176
|
+
(e) => e.name.match(/^data-trackable|^data-o-|^aria-/i)
|
|
177
|
+
).forEach((e) => {
|
|
178
|
+
t[e.name] = e.value;
|
|
179
|
+
}), t), I = (o, t, e) => {
|
|
180
|
+
const n = {};
|
|
181
|
+
return e && A.forEach((r) => {
|
|
182
|
+
typeof t[r] < "u" && r !== "id" && (n[r] = t[r]);
|
|
183
|
+
}), o.filter((r) => r.name.match(/^data-trackable-context-/i)).forEach((r) => {
|
|
184
|
+
n[r.name.replace("data-trackable-context-", "")] = x(r.value);
|
|
185
|
+
}), n;
|
|
186
|
+
};
|
|
187
|
+
function M(o, t) {
|
|
188
|
+
const e = o, n = e != null && e.getAttribute("data-trackable") ? `[data-trackable="${e.getAttribute("data-trackable")}"]` : e == null ? void 0 : e.nodeName, r = [], s = {};
|
|
189
|
+
for (; o && o !== t; ) {
|
|
190
|
+
const i = O(o), c = Array.from(o.attributes);
|
|
191
|
+
let h = D(c, i);
|
|
192
|
+
h["data-trackable"] && (h = Object.assign(
|
|
193
|
+
h,
|
|
194
|
+
N(o, e, n)
|
|
195
|
+
)), r.push(h);
|
|
196
|
+
const a = I(c, i, o === e);
|
|
197
|
+
S(a, s), o = o.parentNode;
|
|
198
|
+
}
|
|
199
|
+
return { trace: r, customContext: s };
|
|
200
|
+
}
|
|
201
|
+
const U = ["ctrlKey", "altKey", "shiftKey", "metaKey"];
|
|
202
|
+
class F {
|
|
203
|
+
constructor({
|
|
204
|
+
id: t = "00000000-0000-0000-0000-000000000000",
|
|
205
|
+
name: e = "ccc-component",
|
|
206
|
+
subtype: n = "interactive",
|
|
207
|
+
teamName: r = "djd",
|
|
208
|
+
shadowRoot: s = null,
|
|
209
|
+
category: i = "cta",
|
|
210
|
+
elements: c = 'a, button, input, [role="button"]',
|
|
211
|
+
logger: h
|
|
212
|
+
}) {
|
|
213
|
+
this.cccId = t, this.cccName = e, this.subtype = n, this.teamName = r, this.shadowRoot = s, this.category = i, this.elements = c, this.isInitialised = !1, this.log = h ?? new T();
|
|
214
|
+
}
|
|
215
|
+
// Get properties for the event (as opposed to properties of the clicked element)
|
|
216
|
+
getEventProperties(t) {
|
|
217
|
+
const e = {};
|
|
218
|
+
for (const n of U)
|
|
219
|
+
if (t[n])
|
|
220
|
+
try {
|
|
221
|
+
e[n] = C(t[n]);
|
|
222
|
+
} catch (r) {
|
|
223
|
+
this.log.info(r);
|
|
224
|
+
}
|
|
225
|
+
return e;
|
|
226
|
+
}
|
|
227
|
+
// Controller for handling click events
|
|
228
|
+
handleClickEvent(t, e) {
|
|
229
|
+
return (n, r) => {
|
|
230
|
+
const s = this.getEventProperties(n), { trace: i, customContext: c } = M(r, e);
|
|
231
|
+
s.custom = r.dataset && r.dataset.custom ? JSON.parse(r.dataset.custom) : null, s.domPathTokens = i, s.component = {
|
|
232
|
+
id: this.cccId,
|
|
233
|
+
name: this.cccName,
|
|
234
|
+
type: "custom-code-component",
|
|
235
|
+
subtype: this.subtype
|
|
236
|
+
}, s.teamName = this.teamName, s.url = document.URL, S(c, s), s.method = "ftCustomAnalytics", t = { ...t, ...s }, document.body.dispatchEvent(
|
|
237
|
+
new CustomEvent("oTracking.event", {
|
|
238
|
+
detail: t,
|
|
239
|
+
bubbles: !0,
|
|
240
|
+
composed: !0
|
|
241
|
+
})
|
|
242
|
+
);
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
sendSpoorEvent(t, e) {
|
|
246
|
+
const n = {
|
|
247
|
+
category: "component",
|
|
248
|
+
action: "act",
|
|
249
|
+
component: {
|
|
250
|
+
id: this.cccId,
|
|
251
|
+
name: this.cccName,
|
|
252
|
+
type: "custom-code-component",
|
|
253
|
+
subtype: this.subtype
|
|
254
|
+
},
|
|
255
|
+
teamName: this.teamName,
|
|
256
|
+
trigger_action: t,
|
|
257
|
+
custom: e,
|
|
258
|
+
method: "ftCustomAnalytics"
|
|
259
|
+
};
|
|
260
|
+
document.body.dispatchEvent(
|
|
261
|
+
new CustomEvent("oTracking.event", {
|
|
262
|
+
detail: n,
|
|
263
|
+
bubbles: !0,
|
|
264
|
+
composed: !0
|
|
265
|
+
})
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
init(t) {
|
|
269
|
+
var e;
|
|
270
|
+
if (!this.isInitialised) {
|
|
271
|
+
this.isInitialised = !0, this.cccId = t || this.cccId;
|
|
272
|
+
const n = {
|
|
273
|
+
action: "click",
|
|
274
|
+
category: this.category
|
|
275
|
+
}, r = (e = this.shadowRoot) == null ? void 0 : e.querySelector("[data-component-root]");
|
|
276
|
+
r && new l(r).on(
|
|
277
|
+
"click",
|
|
278
|
+
this.elements,
|
|
279
|
+
this.handleClickEvent(n, r),
|
|
280
|
+
!0
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
class f {
|
|
286
|
+
constructor(t) {
|
|
287
|
+
this.org = "local", this.repo = "dev";
|
|
288
|
+
const { org: e, repo: n, name: r, versionRange: s } = E(t) ? t : f.fromString(t);
|
|
289
|
+
e && (this.org = e), n && (this.repo = n), this.name = r, this.versionRange = s;
|
|
290
|
+
}
|
|
291
|
+
set path(t) {
|
|
292
|
+
const { org: e, repo: n, name: r, versionRange: s } = E(t) ? t : f.fromString(t);
|
|
293
|
+
this.org = e, this.repo = n, this.name = r, this.versionRange = s;
|
|
294
|
+
}
|
|
295
|
+
get path() {
|
|
296
|
+
return `${this.org}/${this.repo}@${this.versionRange}/${this.name}`;
|
|
297
|
+
}
|
|
298
|
+
toString() {
|
|
299
|
+
return this.path;
|
|
300
|
+
}
|
|
301
|
+
static fromString(t, e) {
|
|
302
|
+
var c;
|
|
303
|
+
if (!t) throw new d("No path specified");
|
|
304
|
+
const [n, r, s] = t.replace(/@[^\/]+/, "").split("/").reverse(), i = e ?? ((c = t.match(/@[^\/]+/)) == null ? void 0 : c.toString().replace("@", "")) ?? "unknown";
|
|
305
|
+
if (r && !i) throw new d("No version specified");
|
|
306
|
+
return new f({ org: s, repo: r, name: n, versionRange: i });
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function E(o) {
|
|
310
|
+
return typeof o == "object" && o !== null ? "org" in o && "repo" in o && "name" in o : !1;
|
|
311
|
+
}
|
|
312
|
+
class d extends Error {
|
|
313
|
+
constructor(t, e) {
|
|
314
|
+
var n;
|
|
315
|
+
!e && t ? (super(t), this.component = null) : typeof (e == null ? void 0 : e.component) == "string" ? (super(
|
|
316
|
+
t ?? `${e.cause ?? "Unknown error"} in ${e.component} imported from ${e.source ?? "an undefined source"}.`
|
|
317
|
+
), this.component = f.fromString(e.component)) : E(e == null ? void 0 : e.component) ? (super(
|
|
318
|
+
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"}.`
|
|
319
|
+
), this.component = new f(e.component)) : (super(
|
|
320
|
+
`${(e == null ? void 0 : e.cause) ?? "Unknown error"} in unknown component imported from ${(e == null ? void 0 : e.source) ?? "unknown source"}.`
|
|
321
|
+
), 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, d), this.name = "CCCError";
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
class g extends d {
|
|
325
|
+
constructor(t, e) {
|
|
326
|
+
super(t, { ...e, cause: "Import error" }), this.name = "CCCImportError";
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
class _ extends d {
|
|
330
|
+
constructor(t, e) {
|
|
331
|
+
super(t, { ...e, cause: "Render error" }), this.name = "CCCRenderError";
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
class j extends d {
|
|
335
|
+
constructor(t) {
|
|
336
|
+
super(null, { ...t, cause: "Timeout error" }), this.name = "CCCTimeoutError";
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const w = class w extends Event {
|
|
340
|
+
constructor(t, e) {
|
|
341
|
+
super(w.eventType, {
|
|
342
|
+
bubbles: !0,
|
|
343
|
+
cancelable: !1,
|
|
344
|
+
composed: !0,
|
|
345
|
+
...e
|
|
346
|
+
}), this.component = t.component, this.source = t.source;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
w.eventType = "ccc:connected";
|
|
350
|
+
let b = w;
|
|
351
|
+
const H = (o) => o.replace(
|
|
352
|
+
/[A-Z]+(?![a-z])|[A-Z]/g,
|
|
353
|
+
(t, e) => (e ? "-" : "") + t.toLowerCase()
|
|
354
|
+
);
|
|
355
|
+
function z(o) {
|
|
356
|
+
return y([
|
|
357
|
+
"localhost",
|
|
358
|
+
"local.ft.com",
|
|
359
|
+
/^.*\.apps\.in\.ft\.com$/
|
|
360
|
+
], o);
|
|
361
|
+
}
|
|
362
|
+
function Y() {
|
|
363
|
+
return y([
|
|
364
|
+
"localhost",
|
|
365
|
+
"local.ft.com",
|
|
366
|
+
/^.*\.in\.ft\.com$/
|
|
367
|
+
], window.location.hostname);
|
|
368
|
+
}
|
|
369
|
+
function q() {
|
|
370
|
+
return y([
|
|
371
|
+
"spark.ft.com",
|
|
372
|
+
"spark-staging.ft.com"
|
|
373
|
+
], window.location.host);
|
|
374
|
+
}
|
|
375
|
+
function y(o, t) {
|
|
376
|
+
return t ? o.some((e) => typeof e == "string" ? e === t : e.test(t)) : !1;
|
|
377
|
+
}
|
|
378
|
+
function V(o) {
|
|
379
|
+
if (o === null)
|
|
380
|
+
return;
|
|
381
|
+
let t;
|
|
382
|
+
const e = new URL("http://localhost:5173");
|
|
383
|
+
try {
|
|
384
|
+
if (typeof o == "string") {
|
|
385
|
+
if ((o === "" || o.toLowerCase() === "true") && Y())
|
|
386
|
+
t = e;
|
|
387
|
+
else if (t = o.startsWith("http://") || o.startsWith("https://") ? new URL(o) : void 0, t && !z(t == null ? void 0 : t.hostname))
|
|
388
|
+
throw new Error("Unsafe testing host override");
|
|
389
|
+
} else q() && (t = e);
|
|
390
|
+
} catch {
|
|
391
|
+
return t;
|
|
392
|
+
}
|
|
393
|
+
return t;
|
|
394
|
+
}
|
|
395
|
+
async function J(o, t) {
|
|
396
|
+
return t ? fetch(
|
|
397
|
+
new URL(`src/${o}/config.yaml`, t),
|
|
398
|
+
{
|
|
399
|
+
method: "HEAD"
|
|
400
|
+
}
|
|
401
|
+
).then(() => !0).catch(() => !1) : !1;
|
|
402
|
+
}
|
|
403
|
+
const W = ":host{width:var(--ccc-root-width, 100%);margin:var(--ccc-root-margin, inherit);padding:var(--ccc-root-padding, inherit);display:var(--ccc-root-display, inherit);font-size:var(--ccc-root-fontSize, inherit);box-sizing:var(--ccc-root-boxSizing, inherit);border:var(--ccc-root-border, inherit);grid:var(--ccc-root-grid, inherit);line-height:var(--ccc-root-lineHeight, inherit)}";
|
|
404
|
+
class K extends HTMLElement {
|
|
405
|
+
constructor() {
|
|
406
|
+
super(), this.mode = "open", this.RESERVED_ATTRS = /* @__PURE__ */ new Set([
|
|
407
|
+
"iframe",
|
|
408
|
+
"path",
|
|
409
|
+
"version",
|
|
410
|
+
"data-component-props",
|
|
411
|
+
"data-asset-type",
|
|
412
|
+
"shadow-open",
|
|
413
|
+
"env",
|
|
414
|
+
"load-timeout"
|
|
415
|
+
]), this.channel = new MessageChannel(), this.initTracking = async () => {
|
|
416
|
+
var e;
|
|
417
|
+
try {
|
|
418
|
+
(e = this.tracking) == null || e.init(this.id);
|
|
419
|
+
} catch (n) {
|
|
420
|
+
const r = this.getAttribute("path"), s = this.getAttribute("version");
|
|
421
|
+
this.log.info(
|
|
422
|
+
`Error initialising tracking on <custom-code-component> ${r}@${s}`
|
|
423
|
+
), this.log.error(n);
|
|
424
|
+
}
|
|
425
|
+
}, this.log = new T({
|
|
426
|
+
level: $(this.getAttribute("log"))
|
|
427
|
+
});
|
|
428
|
+
const t = HTMLElement.prototype.hasOwnProperty("attachInternals");
|
|
429
|
+
try {
|
|
430
|
+
const e = t && this.attachInternals();
|
|
431
|
+
} catch (e) {
|
|
432
|
+
this.log.error(e);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
async connectedCallback() {
|
|
436
|
+
try {
|
|
437
|
+
const t = this.getAttribute("path"), e = this.getAttribute("version");
|
|
438
|
+
this.component = f.fromString(t, e), this.app = await this.load(), await this.mount(), await this.initTracking();
|
|
439
|
+
} catch (t) {
|
|
440
|
+
t instanceof Error && requestAnimationFrame(() => {
|
|
441
|
+
this.emitError(t);
|
|
442
|
+
}), this.unmount(t);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
emitError(t) {
|
|
446
|
+
this.dispatchEvent(new ErrorEvent("ccc:error", {
|
|
447
|
+
bubbles: !0,
|
|
448
|
+
cancelable: !1,
|
|
449
|
+
composed: !0,
|
|
450
|
+
error: t,
|
|
451
|
+
message: t.message
|
|
452
|
+
}));
|
|
453
|
+
}
|
|
454
|
+
disconnectedCallback() {
|
|
455
|
+
const t = this.getAttribute("path");
|
|
456
|
+
this.log.info(`<custom-code-component:${t}> disconnected`), typeof this.onunmount == "function" && this.onunmount();
|
|
457
|
+
}
|
|
458
|
+
onmessage() {
|
|
459
|
+
}
|
|
460
|
+
onunmount(t) {
|
|
461
|
+
}
|
|
462
|
+
async onready(t) {
|
|
463
|
+
try {
|
|
464
|
+
await t;
|
|
465
|
+
} catch (e) {
|
|
466
|
+
if (e instanceof Error) {
|
|
467
|
+
const n = new _(e.message, {
|
|
468
|
+
error: e,
|
|
469
|
+
component: this.component
|
|
470
|
+
});
|
|
471
|
+
requestAnimationFrame(() => {
|
|
472
|
+
this.emitError(n), this.unmount(n);
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
postMessage(t) {
|
|
478
|
+
this.channel.port1.postMessage(t);
|
|
479
|
+
}
|
|
480
|
+
async mount(t) {
|
|
481
|
+
var e, n;
|
|
482
|
+
try {
|
|
483
|
+
if (this.mode = this.getAttribute("shadow-open") == "false" ? "closed" : "open", this.component) {
|
|
484
|
+
if (this.dispatchEvent(
|
|
485
|
+
new b({
|
|
486
|
+
component: this.component,
|
|
487
|
+
source: this.source
|
|
488
|
+
})
|
|
489
|
+
), this.dataset.cccReady = "true", delete this.dataset.cccError, !this.app)
|
|
490
|
+
throw new Error("CCC mounted without App");
|
|
491
|
+
const r = this.shadowRoot !== null, s = this.shadowRoot ?? this.attachShadow({ mode: this.mode });
|
|
492
|
+
if (!s.querySelector('link[href~="custom-code-component.css"]') && !s.adoptedStyleSheets.length && (window.CCC_LAYOUT_STYLESHEET || (window.CCC_LAYOUT_STYLESHEET = new CSSStyleSheet(), window.CCC_LAYOUT_STYLESHEET.replaceSync(W)), s.adoptedStyleSheets = [window.CCC_LAYOUT_STYLESHEET]), !r) {
|
|
493
|
+
const u = document.createElement("template");
|
|
494
|
+
u.innerHTML = "<div data-component-root><slot></slot></div>", this.appendChild(u), s.appendChild(u.content.cloneNode(!0));
|
|
495
|
+
}
|
|
496
|
+
const i = JSON.parse(this.getAttribute("data-component-props")), c = Object.fromEntries(
|
|
497
|
+
[...this.attributes].filter(
|
|
498
|
+
(u) => !this.RESERVED_ATTRS.has(u.name) && !u.name.startsWith("data-")
|
|
499
|
+
).map((u) => [u.name, u.value])
|
|
500
|
+
);
|
|
501
|
+
this.tracking = new F({
|
|
502
|
+
name: (e = this.component) == null ? void 0 : e.toString(),
|
|
503
|
+
subtype: "interactive",
|
|
504
|
+
teamName: "djd",
|
|
505
|
+
shadowRoot: this.shadowRoot,
|
|
506
|
+
logger: this.log
|
|
507
|
+
}), !i && Object.keys(c).length > 0 && (this.log.warn(
|
|
508
|
+
`CCC ${this.component.toString()}: passing component settings as webcomponent attributes is %cDEPRECATED`,
|
|
509
|
+
"font-weight: bold",
|
|
510
|
+
" and will be removed in v3."
|
|
511
|
+
), this.log.warn(
|
|
512
|
+
"Please use the %cdata-component-props",
|
|
513
|
+
"text-decoration: underline;",
|
|
514
|
+
" attribute instead."
|
|
515
|
+
));
|
|
516
|
+
const { unmount: h, onmessage: a, ready: m } = this.app(
|
|
517
|
+
s,
|
|
518
|
+
{
|
|
519
|
+
...i ?? c,
|
|
520
|
+
data: i ?? c,
|
|
521
|
+
port: this.channel.port2,
|
|
522
|
+
tracking: this.tracking,
|
|
523
|
+
prerendered: !!t,
|
|
524
|
+
children: this.children
|
|
525
|
+
},
|
|
526
|
+
r
|
|
527
|
+
) || {};
|
|
528
|
+
h && (this.onunmount = h), a && (this.onmessage = a), m && this.onready(m);
|
|
529
|
+
}
|
|
530
|
+
} catch (r) {
|
|
531
|
+
throw this.log.info(
|
|
532
|
+
`<custom-code-component> uncaught error during mount from ${(n = this.component) == null ? void 0 : n.toString()}`
|
|
533
|
+
), this.log.error(r), r;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
// Called in top-level error handler
|
|
537
|
+
// Replace shadow root with either <slot> or template[data-component-fallback]
|
|
538
|
+
// slot on failure
|
|
539
|
+
unmount(t) {
|
|
540
|
+
var n;
|
|
541
|
+
this.onunmount(t);
|
|
542
|
+
const e = this.querySelector(
|
|
543
|
+
"template[data-component-fallback]"
|
|
544
|
+
) ?? this.querySelector("template");
|
|
545
|
+
e && ((n = this.shadowRoot) == null || n.replaceChildren(e.content.cloneNode(!0))), this.dataset.cccError || (this.dataset.cccError = H(t.name.replace("CCC", ""))), delete this.dataset.cccReady;
|
|
546
|
+
}
|
|
547
|
+
async load() {
|
|
548
|
+
if (!this.component)
|
|
549
|
+
throw new Error("No path found");
|
|
550
|
+
const t = this.getAttribute("path"), e = this.getAttribute("version"), n = Number(this.getAttribute("load-timeout") || 1e4), r = this.getAttribute("test-env"), s = V(r), i = await J(this.component.name, s), c = this.getAttribute("id");
|
|
551
|
+
this.source = i ? `${s == null ? void 0 : s.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}`;
|
|
552
|
+
try {
|
|
553
|
+
return await new Promise(
|
|
554
|
+
(h, a) => {
|
|
555
|
+
const m = setTimeout(() => {
|
|
556
|
+
this.log.error("CCC import timeout error"), a(
|
|
557
|
+
new j({
|
|
558
|
+
component: this.component,
|
|
559
|
+
source: this.source
|
|
560
|
+
})
|
|
561
|
+
);
|
|
562
|
+
}, Number(n));
|
|
563
|
+
if (this.source)
|
|
564
|
+
import(
|
|
565
|
+
/* webpackIgnore: true */
|
|
566
|
+
this.source
|
|
567
|
+
/* @vite-ignore */
|
|
568
|
+
).then(({ default: u }) => {
|
|
569
|
+
if (u)
|
|
570
|
+
clearTimeout(m), h(u);
|
|
571
|
+
else
|
|
572
|
+
throw new g(
|
|
573
|
+
"No component renderer default export found",
|
|
574
|
+
{
|
|
575
|
+
component: this.component,
|
|
576
|
+
source: this.source
|
|
577
|
+
}
|
|
578
|
+
);
|
|
579
|
+
}).catch((u) => {
|
|
580
|
+
clearTimeout(m), this.log.error(u), u instanceof Error && !(u instanceof g) ? a(
|
|
581
|
+
new g(u.message, {
|
|
582
|
+
component: this.component,
|
|
583
|
+
source: this.source
|
|
584
|
+
})
|
|
585
|
+
) : a(u);
|
|
586
|
+
});
|
|
587
|
+
else
|
|
588
|
+
throw clearTimeout(m), new g(`Unable to mount ${t}`, {
|
|
589
|
+
component: this.component,
|
|
590
|
+
source: this.source
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
);
|
|
594
|
+
} catch (h) {
|
|
595
|
+
throw this.log.error(
|
|
596
|
+
`<custom-code-component> error during import from ${t}@${e}`
|
|
597
|
+
), h;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
export {
|
|
602
|
+
K as FTCustomCodeComponent
|
|
603
|
+
};
|
|
604
|
+
//# sourceMappingURL=custom-element.js.map
|